﻿using MauiApp1.Models;

namespace MauiApp1
{
    public class APIService
    {
        private static string _baseUrl = "http://120.27.209.53:8094/";

        public static async Task<CateResponse> GetCate()
        {
            try
            {
                using(var client=new HttpClient())
                {
                    var json = await client.GetStringAsync(_baseUrl + "vod/getCategory");
                    var res = System.Text.Json.JsonSerializer.Deserialize<CateResponse>(json);
                    return res;
                }
            }
            catch (Exception ex)
            {

                return null;
            }
        }

        public static async Task<VideoResponse> GetVideo(int cateId, int page, string wd="")
        {
            try
            {
                var preUrl = $"vod/getVideoList?t={cateId}&pg={page}&wd={wd}";

                using (var client = new HttpClient())
                {
                    var json = await client.GetStringAsync(_baseUrl + preUrl);
                    var res = System.Text.Json.JsonSerializer.Deserialize<VideoResponse>(json);
                    return res;
                }
            }
            catch (Exception ex)
            {

                return null;
            }
        }

        public static async Task<VideoInfoResponse> GetVideoInfo(int videoid)
        {
            try
            {
                var preUrl = $"vod/getVideoUrl?ids={videoid}";

                using (var client = new HttpClient())
                {
                    var json = await client.GetStringAsync(_baseUrl + preUrl);
                    var res = System.Text.Json.JsonSerializer.Deserialize<VideoInfoResponse>(json);
                    return res;
                }
            }
            catch (Exception ex)
            {

                return null;
            }
        }
    }
}
